#include "StdAfx.h"
#include "DFade.h"
#include <SFML/Graphics.hpp>

using namespace Postprocesses;

DFade::DFade(void)
: DIPostprocess()
{
}

DFade::~DFade(void)
{
}

void DFade::update(float dt)
{
    if(m_bIn)
    {
        m_fFadeVal += m_fSpeed*dt;

        if(m_fFadeVal > 1.0f)
        {
            deactivate();
        }
    }
    else
    {
        m_fFadeVal -= m_fSpeed*dt;

        if(m_fFadeVal < 0.0f)
        {
            deactivate();
        }
    }

    m_effect.lock()->SetParameter("fadeValue", m_fFadeVal);
}

void DFade::startFade(bool bIn, float fSpeed)
{
    m_bIn = bIn;

    if(m_bIn)
    {
        m_fFadeVal = 0.0f;
    }
    else
    {
        m_fFadeVal = 1.0f;
    }
    m_fSpeed = fSpeed;

    m_effect.lock()->SetTexture("framebuffer", 0);

    activate();
}